var prefix = ctx + "module/workFlowApply"
var audit_ture="pass";
var audit_false="reject";
$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'user.userName', 
			title : '申请人',
			formatter: function(value, row, index) {
                if (value == null) {
                	return '<span>'+row.registerUser.registerRealname+'</span>';
                }else if (value != null){
                	return '<span>'+row.user.userName+'</span>';
                }
            } 
		},
				{
			field : 'workFlow.flowName', 
			title : '申请的流程类型' 
		},
				{
			field : 'createTime', 
			title : '申请时间' 
		},
				{
			field : 'status', 
			title : '状态',
			formatter: function(value, row, index) {
                if (value == 'ing') {
                	return '<span class="label label-primary">审批中</span>';
                }else if(value == 'reject'){
                	return '<span class="label label-danger">审核被拒</span>';
                }else if(value == 'pass'){
                	return '<span class="label label-success">审核通过</span>';
                }else{
                	return '<span class="label label-warning">未知</span>';
                }
            } 
		},
				{
			field : 'note', 
			title : '备注' 
		},
				
		        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
				
				actions.push('<a class="btn btn-warning btn-sm ' + auditFlag + '" href="#" title="同意" onclick="auditFun(\'' + audit_ture + '\',\'' + row.taskId + '\')"><i class="fa fa-check"></i></a>');
				actions.push('<a class="btn btn-warning btn-sm ' + auditFlag + '" href="#" title="驳回" onclick="auditFun(\'' + audit_false + '\',\'' + row.taskId + '\')"><i class="fa fa-times"></i></a>');
				return actions.join('');
            }
        }];
	
	
	var url = prefix + "/assignList";
	$.initTable(columns, url);
});

/*审批申请-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增审批申请", url);
}

/*审批申请-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改审批申请", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中审批申请吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

//查看我的审批进度
function auditFun(audit,taskId){
	$.modalConfirm("确定提交？", function() {
		_ajax(prefix + '/auditTask/' + taskId+ '/' + audit, "", "get");
    })
	
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("id");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
